package com.itlong.cloud.controller.user;

import com.alibaba.fastjson.JSON;
import com.itlong.cloud.POJO.DTO.app.AppFaceRecognitionDeviceAuthDTO;
import com.itlong.cloud.POJO.DTO.common.PadFaceSyncDataDTO;
import com.itlong.cloud.POJO.DTO.property.CheckAppUserDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyHouseholdRoleAuthDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyHouseholdRoleGetPageDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyHouseholdRoleSaveDTO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.app.AppElevatorAuthVO;
import com.itlong.cloud.POJO.VO.property.*;
import com.itlong.cloud.abstracts.BaseController;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.annotation.LoggerInfo;
import com.itlong.cloud.constants.LogDescConstant;
import com.itlong.cloud.enumerate.AppUserProjectStatusEnum;
import com.itlong.cloud.enumerate.DataStatusEnum;
import com.itlong.cloud.enumerate.PropertyEquipTypeEnum;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.enumerate.ecode.PropertyErrorCodeEnum;
import com.itlong.cloud.equip.property.IPadFaceSyncDataServiceClient;
import com.itlong.cloud.equip.property.IPropertyDeviceAuthServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.user.property.IPropertyHouseHoldInfoServiceClient;
import com.itlong.cloud.user.property.IPropertyHouseholdRoleServiceClient;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.page.Page;
import com.itlong.cloud.utils.words.NumberHandlerUtil;
import com.itlong.cloud.utils.words.StringHandlerUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * <desc>
 *      物业系统住户权限(角色组)分配控制器
 * </desc>
 *
 * @createDate 2019/02/20
 */
@RestController
@RequestMapping(path = "/user/householdRole")
public class PropertyHouseholdRoleController extends BaseController {

    private static Logger LOG = LoggerFactory.getLogger(PropertyHouseholdRoleController.class);

    @Autowired
    private IPropertyHouseholdRoleServiceClient iPropertyHouseholdRoleServiceClient;

    @Autowired
    private IPropertyHouseHoldInfoServiceClient iPropertyHouseHoldInfoServiceClient;

    @Autowired
    private IPropertyDeviceAuthServiceClient iPropertyDeviceAuthServiceClient;

    @Autowired
    private IPadFaceSyncDataServiceClient iPadFaceSyncDataServiceClient;


    /**
     * <desc>
     *      添加住户角色组信息
     * </desc>
     *
     * @param propertyHouseholdRoleSaveDTO 添加住户角色组信息数据DTO
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/02/20
     */
    @ResponseBody
    @PostMapping(path = "save")
    @AuthAccessRequired
    @LoggerInfo(operateDesc = LogDescConstant.HOUSEHOLD_ROLE_SAVE_LOG_DESC)

    public Object saveHouseholdRole(PropertyHouseholdRoleSaveDTO propertyHouseholdRoleSaveDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyHouseholdRoleSaveDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyHouseholdRoleSaveDTO.class, request);
            if (propertyHouseholdRoleSaveDTO == null || StringUtils.isBlank(propertyHouseholdRoleSaveDTO.getRoleName())
                    || StringUtils.isBlank(propertyHouseholdRoleSaveDTO.getProjectId()) || propertyHouseholdRoleSaveDTO.getStatus() == null) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (propertyHouseholdRoleSaveDTO.getRoleName().length() > 25) {
                return new MessageVO(BaseErrorCodeEnum.PARAM_ERR.getErrorCode());
            }
            if (!NumberHandlerUtil.isInRange(propertyHouseholdRoleSaveDTO.getStatus(), 1, 2)) {
                return new MessageVO(BaseErrorCodeEnum.PARAM_ERR.getErrorCode());
            }
            PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO = new PropertyHouseholdRoleGetPageDTO();
            BeanUtils.copyProperties(propertyHouseholdRoleSaveDTO, propertyHouseholdRoleGetPageDTO);
            PropertyHouseholdRoleGetPageVO one = iPropertyHouseholdRoleServiceClient.getOne(propertyHouseholdRoleGetPageDTO);
            if (one != null) {
                return new MessageVO(PropertyErrorCodeEnum.PROPERTY_HOUSEHOLD_ROLE_NAME_EXIST_ERR.getErrorCode());
            }
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),iPropertyHouseholdRoleServiceClient.saveHouseholdRole(propertyHouseholdRoleSaveDTO));
        } catch (Exception e) {
            throw new DataAccessException("【物业-住户管理】添加住户角色组信息失败", e);
        }
    }

    /**
     * <desc>
     *      分页获取住户角色组信息
     * </desc>
     *
     * @param propertyHouseholdRoleGetPageDTO 获取分页住户角色组信息DTO
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/02/21
     */
    @ResponseBody
    @AuthAccessRequired
    @PostMapping(path = "getPage")
    public Object getPage(PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyHouseholdRoleGetPageDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyHouseholdRoleGetPageDTO.class, request);
            if (propertyHouseholdRoleGetPageDTO == null || StringUtils.isBlank(propertyHouseholdRoleGetPageDTO.getProjectId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            //排序
            if (propertyHouseholdRoleGetPageDTO.getOrderColumn() != null && !propertyHouseholdRoleGetPageDTO.getOrderColumn().equals("")) {
                if (propertyHouseholdRoleGetPageDTO.getOrderColumn().equals("createTime")) {
                    propertyHouseholdRoleGetPageDTO.setOrderColumn("create_time");
                }
            }
            Page<PropertyHouseholdRoleGetPageVO> propertyHouseholdRoleGetPageVOPage = iPropertyHouseholdRoleServiceClient.getPage(propertyHouseholdRoleGetPageDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), propertyHouseholdRoleGetPageVOPage);
        } catch (Exception e) {
            throw new DataAccessException("【物业-住户管理】分页获取住户角色组信息失败", e);
        }
    }

    /**
     * <desc>
     *      获取单个住户角色组信息
     * </desc>
     *
     * @param propertyHouseholdRoleGetPageDTO 获取分页住户角色组信息DTO
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/02/21
     */
    @ResponseBody
    @PostMapping(path = "getOne")
    public Object getOne(PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyHouseholdRoleGetPageDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyHouseholdRoleGetPageDTO.class, request);
            if (propertyHouseholdRoleGetPageDTO == null || StringUtils.isBlank(propertyHouseholdRoleGetPageDTO.getProjectId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (StringUtils.isBlank(propertyHouseholdRoleGetPageDTO.getRoleName()) && StringUtils.isBlank(propertyHouseholdRoleGetPageDTO.getRoleId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            PropertyHouseholdRoleGetPageVO propertyHouseholdRoleGetPageVO = iPropertyHouseholdRoleServiceClient.getOne(propertyHouseholdRoleGetPageDTO);

            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), propertyHouseholdRoleGetPageVO);
        } catch (Exception e) {
            throw new DataAccessException("【物业-住户管理】获取单个住户角色组信息失败", e);
        }
    }

    /**
     * <desc>
     *      修改住户角色组信息
     * </desc>
     *
     * @param propertyHouseholdRoleGetPageDTO 获取分页住户角色组信息DTO
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/02/21
     */
    @ResponseBody
    @PostMapping(path = "update")
    @AuthAccessRequired
    @LoggerInfo(operateDesc = LogDescConstant.HOUSEHOLD_ROLE_UPDATE_LOG_DESC)
    public Object update(PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyHouseholdRoleGetPageDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyHouseholdRoleGetPageDTO.class, request);
            if (propertyHouseholdRoleGetPageDTO == null || StringUtils.isBlank(propertyHouseholdRoleGetPageDTO.getRoleName())
                    || StringUtils.isBlank(propertyHouseholdRoleGetPageDTO.getRoleId()) || propertyHouseholdRoleGetPageDTO.getStatus() == null
                    || StringUtils.isBlank(propertyHouseholdRoleGetPageDTO.getProjectId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (!NumberHandlerUtil.isInRange(propertyHouseholdRoleGetPageDTO.getStatus(), 1, 2)) {
                return new MessageVO(BaseErrorCodeEnum.PARAM_ERR.getErrorCode());
            }
            PropertyHouseholdRoleGetPageDTO getOneDTO = new PropertyHouseholdRoleGetPageDTO();
            BeanUtils.copyProperties(propertyHouseholdRoleGetPageDTO, getOneDTO);
            getOneDTO.setRoleId(null);
            PropertyHouseholdRoleGetPageVO one = iPropertyHouseholdRoleServiceClient.getOne(getOneDTO);
            if (one != null && !StringHandlerUtil.compareStrWithOutEmpty(one.getRoleId(), propertyHouseholdRoleGetPageDTO.getRoleId())) {
                return new MessageVO(PropertyErrorCodeEnum.PROPERTY_HOUSEHOLD_ROLE_NAME_EXIST_ERR.getErrorCode());
            }
            // 拿到角色绑定的用户id列表
            List<String> userIdListByRoleId = iPropertyHouseholdRoleServiceClient.getUserIdListByRoleId(propertyHouseholdRoleGetPageDTO.getRoleId());
            List<Map<String,Object>> list = new ArrayList<>();
            for(String userId : userIdListByRoleId) {
                //获取用户临时权限数据
                Map<String, Object> tempAuth = iPropertyHouseHoldInfoServiceClient.getOldUserTempAuth(userId, propertyHouseholdRoleGetPageDTO.getProjectId());
                list.add(tempAuth);
            }

            // 启用禁用之前，对应的授权进行处理
            getOneDTO.setRoleId(propertyHouseholdRoleGetPageDTO.getRoleId());
            getOneDTO.setRoleName(null);
            PropertyHouseholdRoleGetPageVO anotherOne = iPropertyHouseholdRoleServiceClient.getOne(getOneDTO);

            //查询此分组下的电梯设备权限集合
            Map<String,Object> map = iPropertyHouseholdRoleServiceClient.getElevatorListByRoleId(propertyHouseholdRoleGetPageDTO.getRoleId(),"1");
            // 拿到当前项目所有电梯设备序列号字符串
            String allElevatorDevices = iPropertyHouseholdRoleServiceClient.getAllElevatorDeviceUniqueStr(propertyHouseholdRoleGetPageDTO.getProjectId());
            iPropertyHouseholdRoleServiceClient.update(propertyHouseholdRoleGetPageDTO);
            if (anotherOne != null && !propertyHouseholdRoleGetPageDTO.getStatus().equals(anotherOne.getStatus()) && userIdListByRoleId != null && !userIdListByRoleId.isEmpty()) {
                // 拿到当前项目所有普通门禁设备序列号字符串
                String currentDevices = iPropertyHouseholdRoleServiceClient.getAllDeviceUniqueStr(propertyHouseholdRoleGetPageDTO.getProjectId());
                if (StringUtils.isBlank(currentDevices)) {
                    currentDevices = "";
                }
                if (DataStatusEnum.BAN.getType().equals(propertyHouseholdRoleGetPageDTO.getStatus())) {
                    // 角色组被禁用，相关授权受影响
                    for (String userId : userIdListByRoleId) {
                        //由于一个人可以有多个组，此处需过滤该用户在其它分组内是否有该设备权限 若有则过滤掉 若没有则按禁用 去权处理
                        List<String> notGroupEntrance = iPropertyHouseholdRoleServiceClient.getEntranceListByNotInRoleIdAndUserId(propertyHouseholdRoleGetPageDTO.getRoleId(),userId,propertyHouseholdRoleGetPageDTO.getProjectId());
                        String deviceUniqueEntranceStrByNotGroupRoleId = "";
                        if(notGroupEntrance!=null){
                            deviceUniqueEntranceStrByNotGroupRoleId = notGroupEntrance.toString().replace("[", "").replace("]", "").replaceAll(" ","");
                        }
                        iPropertyDeviceAuthServiceClient.updateHouseHoldTmpDeviceAuth(propertyHouseholdRoleGetPageDTO.getLoginUserId(), userId, propertyHouseholdRoleGetPageDTO.getProjectId(), 2
                                , currentDevices, deviceUniqueEntranceStrByNotGroupRoleId, new ArrayList<>(), "mark");

                        //处理用户电梯设备权限表信息
                        if(map!=null && map.size()>0){
                            Map<String,Object> notGroupMap = iPropertyHouseholdRoleServiceClient.getElevatorListByNotInRoleIdAndUserId(propertyHouseholdRoleGetPageDTO.getRoleId(),userId,propertyHouseholdRoleGetPageDTO.getProjectId());
                            String deviceUniqueStrElevatorNotGroupByRoleId = "";
                            List<String> floorNotGroupArr = new ArrayList<>();
                            if(notGroupMap!=null && notGroupMap.size()>0 ){
                                List<String> deviceUniqueByNotGroupElevatorArr = (List<String>) notGroupMap.get("deviceUniqueArr");
                                floorNotGroupArr =(List<String>)  notGroupMap.get("floorArr");
                                deviceUniqueStrElevatorNotGroupByRoleId = deviceUniqueByNotGroupElevatorArr.toString().replace("[", "").replace("]", "").replaceAll(" ","");
                            }
                            iPropertyDeviceAuthServiceClient.updateHouseHoldTmpDeviceAuth(propertyHouseholdRoleGetPageDTO.getLoginUserId(), userId, propertyHouseholdRoleGetPageDTO.getProjectId(), 1
                                    , allElevatorDevices, deviceUniqueStrElevatorNotGroupByRoleId, floorNotGroupArr, "mark");
                        }
                    }
                } else {
                    // 角色组被启用，相关授权受影响
                    // 拿到角色绑定的设备序列号列表
                    List<String> deviceUniqueListByRoleId = iPropertyHouseholdRoleServiceClient.getDeviceUniqueListByRoleId(propertyHouseholdRoleGetPageDTO.getRoleId(),"2");
                    //查询此分组下的电梯设备权限集合
                    Map<String,Object> map1 = iPropertyHouseholdRoleServiceClient.getElevatorListByRoleId(propertyHouseholdRoleGetPageDTO.getRoleId(),"1");
                    if ((deviceUniqueListByRoleId != null && !deviceUniqueListByRoleId.isEmpty()) || (map1 != null && map1.size()>0)) {
                        for (String userId : userIdListByRoleId) {

                            if(deviceUniqueListByRoleId != null && !deviceUniqueListByRoleId.isEmpty()){
                                //处理门禁相关权限 由于一个人可以属于多个组，故此处还需取用户非当前分组的设备机号权限与当前分组的权限机号并集
                                List<String> notGroupEntrance = iPropertyHouseholdRoleServiceClient.getEntranceListByNotInRoleIdAndUserId("",userId,propertyHouseholdRoleGetPageDTO.getProjectId());
                                if(notGroupEntrance!=null){
                                    deviceUniqueListByRoleId.addAll(notGroupEntrance);
                                }
                                String deviceUniqueStrByRoleId = deviceUniqueListByRoleId.toString().replace("[", "").replace("]", "").replaceAll(" ","");
                                iPropertyDeviceAuthServiceClient.updateHouseHoldTmpDeviceAuth(propertyHouseholdRoleGetPageDTO.getLoginUserId(), userId, propertyHouseholdRoleGetPageDTO.getProjectId(), 2
                                        , currentDevices, deviceUniqueStrByRoleId, new ArrayList<>(), "mark");
                            }

                            //处理用户电梯设备权限表信息
                            if(map1!=null && map1.size()>0){
                                //由于一个人可以属于多个组，故此处取出所有的分组权限电梯机号及楼层再重新更新 电梯权限表的6类型的分组权限数据
                                Map<String,Object> notGroupMap = iPropertyHouseholdRoleServiceClient.getElevatorListByNotInRoleIdAndUserId("",userId,propertyHouseholdRoleGetPageDTO.getProjectId());
                                if(notGroupMap!=null && notGroupMap.size()>0){
                                    List<String> deviceUniqueByNotGroupElevatorArr = (List<String>) notGroupMap.get("deviceUniqueArr");
                                    List<String> floorNotGroupArr =(List<String>)  notGroupMap.get("floorArr");
                                    String deviceUniqueStrElevatorByRoleId = deviceUniqueByNotGroupElevatorArr.toString().replace("[", "").replace("]", "").replaceAll(" ","");
                                    iPropertyDeviceAuthServiceClient.updateHouseHoldTmpDeviceAuth(propertyHouseholdRoleGetPageDTO.getLoginUserId(), userId, propertyHouseholdRoleGetPageDTO.getProjectId(), 1
                                            , allElevatorDevices, deviceUniqueStrElevatorByRoleId, floorNotGroupArr, "mark");
                                }
                            }
                        }
                    }


                }

                for(Map<String,Object> tempAuth : list) {
                    //推送临时权限数据
                    iPropertyHouseHoldInfoServiceClient.pushTempUserInfos(propertyHouseholdRoleGetPageDTO.getProjectId(), tempAuth.get("userId").toString(), StringHandlerUtil.getNullOrStringForObject(tempAuth.get("doorAuth")),
                            StringHandlerUtil.getNullOrStringForObject(tempAuth.get("elevatorAuth")), StringHandlerUtil.getNullOrStringForObject(tempAuth.get("talkAuth")),"3");
                }
                //处理该分组下的电梯设备权限表信息
                Map<String,Object> elevatorListByRoleIdMap = iPropertyHouseholdRoleServiceClient.getElevatorListByRoleId(propertyHouseholdRoleGetPageDTO.getRoleId(),"1");
                List<String> deviceUniqueListByRoleId = iPropertyHouseholdRoleServiceClient.getDeviceUniqueListByRoleId(propertyHouseholdRoleGetPageDTO.getRoleId(),"1");
                List<String> userIdList = iPropertyHouseholdRoleServiceClient.getUserIdListByRoleId(propertyHouseholdRoleGetPageDTO.getRoleId());
                //处理平板用户信息 如果该组内无设备 无人员则无须处理平板指令推送
                if(((elevatorListByRoleIdMap!=null && elevatorListByRoleIdMap.size()>0) || !deviceUniqueListByRoleId.isEmpty()) &&!userIdList.isEmpty()){
                    AppFaceRecognitionDeviceAuthDTO appFaceRecognitionDeviceAuthDTO = new AppFaceRecognitionDeviceAuthDTO();
                    appFaceRecognitionDeviceAuthDTO.setUserIdList(userIdList);
                    appFaceRecognitionDeviceAuthDTO.setDeviceUniqueListByRoleId(deviceUniqueListByRoleId);
                    appFaceRecognitionDeviceAuthDTO.setProjectId(propertyHouseholdRoleGetPageDTO.getProjectId());
                    appFaceRecognitionDeviceAuthDTO.setStatus(propertyHouseholdRoleGetPageDTO.getStatus());
                    appFaceRecognitionDeviceAuthDTO.setElevatorListByRoleIdMap(elevatorListByRoleIdMap);
                    appFaceRecognitionDeviceAuthDTO.setRoleId(propertyHouseholdRoleGetPageDTO.getRoleId());
                    new Thread(() -> {
                        try{
                            //此处推送平板指令
                            iPadFaceSyncDataServiceClient.padRoleStatusBussiness(appFaceRecognitionDeviceAuthDTO);
                            //此处处理推送动态人脸识别系统权限指令
                            if(userIdList!=null && userIdList.size()>0){
                                List<String> userIdListByFace = iPropertyHouseholdRoleServiceClient.getUserIdFaceListByRoleId(appFaceRecognitionDeviceAuthDTO.getRoleId(),appFaceRecognitionDeviceAuthDTO.getProjectId());
                                for(String userInfoByFace : userIdListByFace){
                                    PadFaceSyncDataDTO padFaceSyncDataDTO = new PadFaceSyncDataDTO();
                                    padFaceSyncDataDTO.setOperateType("6");
                                    padFaceSyncDataDTO.setAppUserIds(userInfoByFace);
                                    padFaceSyncDataDTO.setProjectId(appFaceRecognitionDeviceAuthDTO.getProjectId());
                                    padFaceSyncDataDTO.setStatus("1");
                                    padFaceSyncDataDTO.setSourceSystem(2);
                                    iPadFaceSyncDataServiceClient.userOrFloorSyncSmartCard(padFaceSyncDataDTO);
                                }
                            }
                        } catch (Exception e) {
                            throw new DataAccessException("【物业-住户管理】修改住户角色组推送平板指令失败", e);
                        }
                    }).start();

                }
            }

            return new MessageVO(propertyHouseholdRoleGetPageDTO.getRoleId(), BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【物业-住户管理】修改住户角色组信息失败", e);
        }
    }

    /**
     * <desc>
     *      删除住户角色组信息
     * </desc>
     *
     * @param propertyHouseholdRoleGetPageDTO 获取分页住户角色组信息DTO
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/02/21
     */
    @ResponseBody
    @PostMapping(path = "delete")
    @AuthAccessRequired
    @LoggerInfo(operateDesc = LogDescConstant.HOUSEHOLD_ROLE_DELETE_LOG_DESC)
    public Object delete(PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyHouseholdRoleGetPageDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyHouseholdRoleGetPageDTO.class, request);
            if (propertyHouseholdRoleGetPageDTO == null || StringUtils.isBlank(propertyHouseholdRoleGetPageDTO.getRoleId())
                    || StringUtils.isBlank(propertyHouseholdRoleGetPageDTO.getProjectId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            // 校验是否有数据关联
            int checkInt = iPropertyHouseholdRoleServiceClient.checkRoleData(propertyHouseholdRoleGetPageDTO);
            if (checkInt == 1) {
                return new MessageVO(PropertyErrorCodeEnum.DELETE_DATA_RELATION_ERR.getErrorCode());
            }
            iPropertyHouseholdRoleServiceClient.delete(propertyHouseholdRoleGetPageDTO);
            return new MessageVO(propertyHouseholdRoleGetPageDTO.getRoleId(), BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【物业-住户管理】删除住户角色组信息失败", e);
        }
    }

    /**
     * <desc>
     *      启用禁用住户角色组信息
     * </desc>
     *
     * @param propertyHouseholdRoleGetPageDTO 获取分页住户角色组信息DTO
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/02/21
     */
//    @ResponseBody
//    @PostMapping(path = "setEnable")
//    @AuthAccessRequired
//    @LoggerInfo(operateDesc = LogDescConstant.HOUSEHOLD_ROLE_SET_ENABLE_LOG_DESC)
//    public Object setEnable(PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO) {
//        try {
//            if (propertyHouseholdRoleGetPageDTO == null || StringUtils.isBlank(propertyHouseholdRoleGetPageDTO.getRoleId())
//                    || StringUtils.isBlank(propertyHouseholdRoleGetPageDTO.getProjectId())) {
//                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
//            }
//            if (!NumberHandlerUtil.isInRange(propertyHouseholdRoleGetPageDTO.getStatus(), 1, 2)) {
//                return new MessageVO(BaseErrorCodeEnum.PARAM_ERR.getErrorCode());
//            }
//            propertyHouseholdRoleGetPageDTO.setRoleName(null);
//            iPropertyHouseholdRoleServiceClient.update(propertyHouseholdRoleGetPageDTO);
//            return new MessageVO(propertyHouseholdRoleGetPageDTO.getRoleId(), BaseErrorCodeEnum.SUCCESS.getErrorCode());
//        } catch (Exception e) {
//            throw new DataAccessException("【物业-住户管理】启用禁用住户角色组信息失败", e);
//        }
//    }

    /**
     * <desc>
     *      分页获取门禁设备列表信息
     * </desc>
     *
     * @param propertyHouseholdRoleGetPageDTO 获取分页住户角色组信息DTO
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/02/21
     */
    @ResponseBody
    @PostMapping(path = "getEntrancePage")
    public Object getEntrancePage(PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyHouseholdRoleGetPageDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyHouseholdRoleGetPageDTO.class, request);
            if (propertyHouseholdRoleGetPageDTO == null || StringUtils.isBlank(propertyHouseholdRoleGetPageDTO.getRoleId())
                    || StringUtils.isBlank(propertyHouseholdRoleGetPageDTO.getProjectId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            List<String> deviceUniqueListByRoleId = iPropertyHouseholdRoleServiceClient.getDeviceUniqueListByRoleId(propertyHouseholdRoleGetPageDTO.getRoleId(),"1");
            StringBuilder deviceUniqueByRoleId = new StringBuilder();
            if (deviceUniqueListByRoleId != null && !deviceUniqueListByRoleId.isEmpty()) {
                for (String deviceUnique : deviceUniqueListByRoleId) {
                    if (deviceUniqueByRoleId.length() == 0) {
                        deviceUniqueByRoleId.append(deviceUnique);
                    } else {
                        deviceUniqueByRoleId.append(",").append(deviceUnique);
                    }
                }
            }
            Page<PropertyHouseholdRoleEntranceGetPageVO> propertyHouseholdRoleEntranceGetPageVOS = iPropertyHouseholdRoleServiceClient.getEntrancePage(propertyHouseholdRoleGetPageDTO);
            return new MessageVO(deviceUniqueByRoleId.toString(),BaseErrorCodeEnum.SUCCESS.getErrorCode(), propertyHouseholdRoleEntranceGetPageVOS);
        } catch (Exception e) {
            throw new DataAccessException("【物业-住户管理】分页获取门禁设备列表信息失败", e);
        }
    }

    /**
     * <desc>
     *      分页获取人员列表信息
     * </desc>
     *
     * @param checkAppUserDTO 查询已入住的App用户信息数据传输对象(前端传给后端)
     * @param roleId          角色ID
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/02/21
     */
    @ResponseBody
    @PostMapping(path = "getUserPage")
    public Object getUserPage(CheckAppUserDTO checkAppUserDTO, String roleId) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            checkAppUserDTO = HttpProtocolUtil.parseRequestParamToDTO(CheckAppUserDTO.class, request);
            roleId = request.getAttribute("roleId") == null ? null : request.getAttribute("roleId").toString();
            if (checkAppUserDTO == null) {
                return new MessageVO(PropertyErrorCodeEnum.APPUSER_USERINFO_NOT_NULL.getErrorCode());
            }
            if (StringUtils.isBlank(checkAppUserDTO.getProjectId())) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            if (StringUtils.isBlank(roleId)) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            checkAppUserDTO.setUserRoomStatus(2);
            //是否需要限制用户id
//            if (checkAppUserDTO.getCheck() == null || checkAppUserDTO.getCheck().equals("") || checkAppUserDTO.getCheck().equals("0,1") || checkAppUserDTO.getCheck().equals("1,0")) {
//                checkAppUserDTO.setCheck("no");
//            } else if (checkAppUserDTO.getCheck().equals("0")) {
//                checkAppUserDTO.setCheck("not in");
//            } else {
//                checkAppUserDTO.setCheck("in");
//            }
            List<String> userIdList = iPropertyHouseholdRoleServiceClient.getUserIdListByRoleId(roleId);
//            if (userIdList.size() > 0) {
//                checkAppUserDTO.setUserIdsLimit(StringUtils.join(userIdList, ","));
//            } else {
//                checkAppUserDTO.setUserIdsLimit("-1");
//            }
            //排序
            if(StringUtils.isBlank(checkAppUserDTO.getOrderColumn())){
                checkAppUserDTO.setOrderColumn("u.create_time");
            }
            if(StringUtils.isBlank(checkAppUserDTO.getOrderRule())){
                checkAppUserDTO.setOrderRule("DESC");
            }
            // 先用住户信息那边的接口分页查出对应住户信息
//            Page<AppUserInfoGetVO> result = iPropertyHouseHoldInfoServiceClient.getCheckUserListForHouseHold(checkAppUserDTO);
            Page<AppUserInfoGetVO> result = iPropertyHouseHoldInfoServiceClient.getCheckUserList(checkAppUserDTO);
            Page<AppUserInfoGetAssembleVO> page = new Page<>();
            page.setPage(result.getPage());
            page.setRows(this.assembleAppUserInfoGetVO(result.getRows()));
            // 验用户是否选中，即isChecked字段 // 是否选中，0否，1是
            StringBuilder roleUserIds = new StringBuilder();
            if (userIdList != null && !userIdList.isEmpty()) {
                for (AppUserInfoGetAssembleVO appUserInfoGetAssembleVO : page.getRows()) {
                    if (userIdList.contains(appUserInfoGetAssembleVO.getUserId())) {
                        appUserInfoGetAssembleVO.setIsChecked("1");
                    } else {
                        appUserInfoGetAssembleVO.setIsChecked("0");
                    }
                }
                for (String userId : userIdList) {
                    if (roleUserIds.length() == 0) {
                        roleUserIds.append(userId);
                    } else {
                        roleUserIds.append(",").append(userId);
                    }
                }
            }
            return new MessageVO(roleUserIds.toString(),BaseErrorCodeEnum.SUCCESS.getErrorCode(), page);
        } catch (Exception e) {
            throw new DataAccessException("【物业-住户管理】分页获取人员列表信息失败", e);
        }
    }

    /**
     * <desc>
     *      住户角色组信息设备授权
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/02/22
     */
    @ResponseBody
    @PostMapping(path = "deviceAuth")
    @AuthAccessRequired
    @LoggerInfo(operateDesc = LogDescConstant.HOUSEHOLD_ROLE_DEVICE_AUTH_LOG_DESC)
    public Object deviceAuth(PropertyHouseholdRoleAuthDTO propertyHouseholdRoleAuthDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyHouseholdRoleAuthDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyHouseholdRoleAuthDTO.class, request);
            if (propertyHouseholdRoleAuthDTO == null || StringUtils.isBlank(propertyHouseholdRoleAuthDTO.getRoleId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (StringUtils.isBlank(propertyHouseholdRoleAuthDTO.getProjectId())) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            if(StringUtils.isBlank(propertyHouseholdRoleAuthDTO.getCurrentDeviceUniques())) {
                return new MessageVO(PropertyErrorCodeEnum.APPUSER_DEVICEINFO_ERR.getErrorCode());
            }

            List<String> currentDeviceUniques = StringHandlerUtil.splitStringList(propertyHouseholdRoleAuthDTO.getCurrentDeviceUniques());
            Integer deviceType = StringHandlerUtil.strToIntDef(
                    StringHandlerUtil.copySubStr(currentDeviceUniques.get(0), 8, 1), -1);
            if (deviceType == -1) {
                return new MessageVO(PropertyErrorCodeEnum.APPUSER_DEVICEINFO_ERR.getErrorCode());
            }
            propertyHouseholdRoleAuthDTO.setDeviceType(deviceType);
            //若是电梯设备且有选中设备则楼层信息不会为空，解析后的楼层信息naturalfloorList的size应和选中电梯设备数量一致
            List<String> naturalFloorList = new ArrayList<>();
            if (deviceType == PropertyEquipTypeEnum.ELEVATOR.getType()) {
                List<String> naturalFloors;
                try {
                    naturalFloors = JSON.parseArray(propertyHouseholdRoleAuthDTO.getNaturalFloors(), String.class);
                } catch (Exception e) {
                    throw new DataAccessException("【物业系统_住户信息管理_更新用户设备权限】数据格式有误", e);
                }
                String[] deviceArr = StringHandlerUtil.splitString(propertyHouseholdRoleAuthDTO.getDeviceUniques());
                //此处处理通过筛选条件只变更群控器下的一个电梯，此时群控器下的其他电梯也需一块处理
                for(String elevator:deviceArr){
                    List<String> list = iPropertyHouseholdRoleServiceClient.getCloudControllerElevatorInfo(elevator);
                    if(list!=null){
                        for(String devcieUnqiue : list){
                            if(!propertyHouseholdRoleAuthDTO.getDeviceUniques().contains(devcieUnqiue)){
                                propertyHouseholdRoleAuthDTO.setDeviceUniques(propertyHouseholdRoleAuthDTO.getDeviceUniques()+","+devcieUnqiue);
                                String naturalFloor = propertyHouseholdRoleAuthDTO.getNaturalFloors();
                                propertyHouseholdRoleAuthDTO.setNaturalFloors(naturalFloor.substring(0,naturalFloor.length()-1)+",'"+naturalFloors.get(Arrays.asList(deviceArr).indexOf(elevator))+"']");
                            }
                        }
                    }
                }
                try {
                    naturalFloors = JSON.parseArray(propertyHouseholdRoleAuthDTO.getNaturalFloors(), String.class);
                } catch (Exception e) {
                    throw new DataAccessException("【物业系统_住户信息管理_更新用户设备权限】数据格式有误", e);
                }
                //移除未选择楼层的项
                for (int floorIndex = naturalFloors.size() - 1; floorIndex>=0; floorIndex--){
                    if (StringUtils.isNotBlank(naturalFloors.get(floorIndex))){
                        naturalFloorList.add(naturalFloors.get(floorIndex));
                    }
                }
                //楼层是否为空
                boolean isNull = false;
                if (!naturalFloorList.isEmpty()) {
                    for (String naturalFloor:naturalFloorList) {
                        if (StringUtils.isBlank(naturalFloor)) {
                            isNull = true;
                        }
                    }
                } else {
                    isNull = true;
                }
                //电梯设备机号和楼层不同时为空时有误
                if ((StringUtils.isNotBlank(propertyHouseholdRoleAuthDTO.getDeviceUniques())
                        && propertyHouseholdRoleAuthDTO.getDeviceUniques().replace(",", "").length() > 0 && isNull)
                        || (StringUtils.isBlank(propertyHouseholdRoleAuthDTO.getDeviceUniques()) && !isNull)) {
                    return new MessageVO(PropertyErrorCodeEnum.APPUSER_DEVICEINFO_ELEVATOR_FLOOR_ERR.getErrorCode());
                }
                //同时不为空，判断数量是否相同
                if (StringUtils.isBlank(propertyHouseholdRoleAuthDTO.getDeviceUniques()) && !isNull) {
                    List<String> selectDeviceList = new ArrayList<>();
                    List<String> selectDevice = Arrays.asList(propertyHouseholdRoleAuthDTO.getDeviceUniques().split(","));
                    //移除未选择设备的项
                    for (int floorIndex = selectDevice.size() - 1; floorIndex>=0; floorIndex--){
                        if (StringUtils.isNotBlank(selectDevice.get(floorIndex))){
                            selectDeviceList.add(selectDevice.get(floorIndex));
                        }
                    }
                    if (selectDeviceList.size() != naturalFloorList.size()) {
                        return new MessageVO(PropertyErrorCodeEnum.APPUSER_DEVICEINFO_ELEVATOR_FLOOR_ERR.getErrorCode());
                    }
                }
            }

            //用户授权数据固化之前先整合平板需要的信息
            //拿到更新之前的云门禁设备信息
            List<String> deviceUniqueListByRoleIdOld = iPropertyHouseholdRoleServiceClient.getDeviceUniqueListByRoleId(propertyHouseholdRoleAuthDTO.getRoleId(),"1");
            //拿到更新之前的电梯设备信息
            List<String> deviceUniqueByElevatorArrOld = new ArrayList<>();
            if(deviceType==1){
                Map<String,Object> mapOld = iPropertyHouseholdRoleServiceClient.getElevatorListByRoleId(propertyHouseholdRoleAuthDTO.getRoleId(),"1");
                if(mapOld!=null && mapOld.size()>0) {
                    deviceUniqueByElevatorArrOld = (List<String>) mapOld.get("deviceUniqueArr");
                }
            }

            // 先进行住户角色组的设备授权
            iPropertyHouseholdRoleServiceClient.deviceAuth(propertyHouseholdRoleAuthDTO);

            //拿到更新之后的门禁设备信息
            Thread.sleep(500);//保证数据一致性
            List<String> deviceUniqueListByRoleIdNew = iPropertyHouseholdRoleServiceClient.getDeviceUniqueListByRoleId(propertyHouseholdRoleAuthDTO.getRoleId(),"1");
            //拿到更新之后的电梯设备信息
            List<String> deviceUniqueByElevatorArrNew = new ArrayList<>();
            if(deviceType==1){
                Map<String,Object> mapNew = iPropertyHouseholdRoleServiceClient.getElevatorListByRoleId(propertyHouseholdRoleAuthDTO.getRoleId(),"1");
                if(mapNew!=null && mapNew.size()>0) {
                    deviceUniqueByElevatorArrNew = (List<String>) mapNew.get("deviceUniqueArr");
                }
            }

            // 再同步用户门禁设备权限表信息
            // 拿到角色绑定的用户id列表
            List<String> userIdListByRoleId = iPropertyHouseholdRoleServiceClient.getUserIdListByRoleId(propertyHouseholdRoleAuthDTO.getRoleId());
            List<Map<String,Object>> list = new ArrayList<>();
            for(String userId : userIdListByRoleId) {
                //获取用户临时权限数据
                Map<String, Object> tempAuth = iPropertyHouseHoldInfoServiceClient.getOldUserTempAuth(userId, propertyHouseholdRoleAuthDTO.getProjectId());
                list.add(tempAuth);
            }
            // 拿到当前项目所有门禁设备序列号字符串
            String currentDevices = iPropertyHouseholdRoleServiceClient.getAllDeviceUniqueStr(propertyHouseholdRoleAuthDTO.getProjectId());
            if (StringUtils.isBlank(currentDevices)) {
                currentDevices = "";
            }
            if (userIdListByRoleId != null && !userIdListByRoleId.isEmpty()) {
                // 拿到当前项目所有电梯设备序列号字符串
                String allElevatorDevices = iPropertyHouseholdRoleServiceClient.getAllElevatorDeviceUniqueStr(propertyHouseholdRoleAuthDTO.getProjectId());
                allElevatorDevices = iPropertyHouseholdRoleServiceClient.getDeviceUniqueIdList(allElevatorDevices, propertyHouseholdRoleAuthDTO.getProjectId()).trim();
                for (String userId : userIdListByRoleId) {
                    if(deviceType == PropertyEquipTypeEnum.ENTRANCE.getType()){
                        //处理门禁相关权限逻辑 首先查出目前指定用户权限类型为6的所有权限集合 更新组内用户的权限
                        //由于一个人可以属于多个组，故此处还需取用户非当前分组的设备机号权限与当前分组的权限机号并集
                        List<String> notGroupEntrance = iPropertyHouseholdRoleServiceClient.getEntranceListByNotInRoleIdAndUserId("",userId,propertyHouseholdRoleAuthDTO.getProjectId());
                        if(notGroupEntrance!=null && notGroupEntrance.size()>0){
                            String deviceUniqueStrByRoleId = notGroupEntrance.toString().replace("[", "").replace("]", "").replaceAll(" ","");
                            iPropertyDeviceAuthServiceClient.updateHouseHoldTmpDeviceAuth(propertyHouseholdRoleAuthDTO.getLoginUserId(), userId, propertyHouseholdRoleAuthDTO.getProjectId(), 2
                                    , currentDevices, deviceUniqueStrByRoleId, new ArrayList<>(), "mark");
                        }
                    }
                    if(deviceType == PropertyEquipTypeEnum.ELEVATOR.getType()){
                        //处理电梯相关权限逻辑 首先查出目前指定用户权限类型为6的所有权限集合 更新组内用户的权限
                        Map<String,Object> notGroupMap = iPropertyHouseholdRoleServiceClient.getElevatorListByNotInRoleIdAndUserId("",userId,propertyHouseholdRoleAuthDTO.getProjectId());
                        String deviceUniqueStrElevatorNotGroupByRoleId = "";
                        List<String> floorNotGroupArr = new ArrayList<>();
                        if(notGroupMap!=null && notGroupMap.size()>0 ){
                            List<String> deviceUniqueByNotGroupElevatorArr = (List<String>) notGroupMap.get("deviceUniqueArr");
                            floorNotGroupArr =(List<String>)  notGroupMap.get("floorArr");
                            deviceUniqueStrElevatorNotGroupByRoleId = deviceUniqueByNotGroupElevatorArr.toString().replace("[", "").replace("]", "").replaceAll(" ","");
                        }
                        iPropertyDeviceAuthServiceClient.updateHouseHoldTmpDeviceAuth(propertyHouseholdRoleAuthDTO.getLoginUserId(), userId, propertyHouseholdRoleAuthDTO.getProjectId(), 1
                                , allElevatorDevices, deviceUniqueStrElevatorNotGroupByRoleId, floorNotGroupArr, "mark");
                    }
                }
            }
            for(Map<String,Object> tempAuth : list) {
                if(deviceType == PropertyEquipTypeEnum.ENTRANCE.getType()){
                    //推送云门禁临时权限数据
                    iPropertyHouseHoldInfoServiceClient.pushTempUserInfos(propertyHouseholdRoleAuthDTO.getProjectId(), tempAuth.get("userId").toString(), StringHandlerUtil.getNullOrStringForObject(tempAuth.get("doorAuth")),
                            StringHandlerUtil.getNullOrStringForObject(tempAuth.get("elevatorAuth")), StringHandlerUtil.getNullOrStringForObject(tempAuth.get("talkAuth")),"2");
                }
                if(deviceType == PropertyEquipTypeEnum.ELEVATOR.getType()){
                    //推送云电梯临时权限数据
                    iPropertyHouseHoldInfoServiceClient.pushTempUserInfos(propertyHouseholdRoleAuthDTO.getProjectId(), tempAuth.get("userId").toString(), StringHandlerUtil.getNullOrStringForObject(tempAuth.get("doorAuth")),
                            StringHandlerUtil.getNullOrStringForObject(tempAuth.get("elevatorAuth")), StringHandlerUtil.getNullOrStringForObject(tempAuth.get("talkAuth")),"1");
                }
            }
            //推送平板指令相关处理
            this.doPadDeviceBusiness(deviceUniqueListByRoleIdOld,deviceUniqueListByRoleIdNew,propertyHouseholdRoleAuthDTO,
                    deviceUniqueByElevatorArrOld,deviceUniqueByElevatorArrNew,deviceType);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【物业-住户管理】住户角色组信息设备授权失败", e);
        }
    }

    /**
     * <desc>
     *      处理平板设备指令相关业务
     * </desc>
     *
     * @param deviceUniqueListByRoleIdOld 旧设备信息
     * @param deviceUniqueListByRoleIdNew 当前设备信息
     * @return 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2020/03/09
     */
    private void doPadDeviceBusiness(List<String> deviceUniqueListByRoleIdOld, List<String> deviceUniqueListByRoleIdNew, PropertyHouseholdRoleAuthDTO propertyHouseholdRoleAuthDTO,
                                    List<String> deviceUniqueByElevatorArrOld,List<String> deviceUniqueByElevatorArrNew,Integer deviceType) throws Exception {

        List<String> deleteDeviceUnique = new ArrayList<>();
        List<String> addDeviceUnique = new ArrayList<>();
        List<String> deleteElevatorDeviceUnique = new ArrayList<>();
        List<String> addElevatorDeviceUnique = new ArrayList<>();
        if(deviceType==2){
            //门禁  确认哪些设备新增,哪些设备取消
            for (String deviceUniqueOld : deviceUniqueListByRoleIdOld) {//旧的和新的比找出减少的
                int flag = 0;
                for (String deviceUniqueNew : deviceUniqueListByRoleIdNew) {
                    if (deviceUniqueOld.equals(deviceUniqueNew)) {
                        flag = 1;
                        break;
                    }
                }
                if (flag == 0) {//没有任何一样的证明是减少了的设备
                    deleteDeviceUnique.add(deviceUniqueOld);
                }
            }

            for (String deviceUniqueNew : deviceUniqueListByRoleIdNew) {//新的和旧的比找出新增的
                int flag = 0;
                for (String deviceUniqueOld : deviceUniqueListByRoleIdOld) {
                    if (deviceUniqueNew.equals(deviceUniqueOld)) {
                        flag = 1;
                        break;
                    }
                }
                if (flag == 0) {//没有任何一样的证明是新增了的设备
                    addDeviceUnique.add(deviceUniqueNew);
                }
            }
        }

        if(deviceType==1){
            //电梯  确认哪些设备新增,哪些设备取消
            for (String deviceUniqueOld : deviceUniqueByElevatorArrOld) {//旧的和新的比找出减少的
                int flag = 0;
                for (String deviceUniqueNew : deviceUniqueByElevatorArrNew) {
                    if (deviceUniqueOld.equals(deviceUniqueNew)) {
                        flag = 1;
                        break;
                    }
                }
                if (flag == 0) {//没有任何一样的证明是减少了的设备
                    deleteElevatorDeviceUnique.add(deviceUniqueOld);
                }
            }

            for (String deviceUniqueNew : deviceUniqueByElevatorArrNew) {//新的和旧的比找出新增的
                int flag = 0;
                for (String deviceUniqueOld : deviceUniqueByElevatorArrOld) {
                    if (deviceUniqueNew.equals(deviceUniqueOld)) {
                        flag = 1;
                        break;
                    }
                }
                if (flag == 0) {//没有任何一样的证明是新增了的设备
                    addElevatorDeviceUnique.add(deviceUniqueNew);
                }
            }
        }
        // 验用户是否选中，即isChecked字段 // 是否选中，0否，1是
        List<String> userIdList = iPropertyHouseholdRoleServiceClient.getUserIdFaceListByRoleId(propertyHouseholdRoleAuthDTO.getRoleId(),propertyHouseholdRoleAuthDTO.getProjectId());
        //平板普通门禁业务指令处理
        if(deleteDeviceUnique.size() == 0 && addDeviceUnique.size() == 0 && addElevatorDeviceUnique.size()==0 && deleteElevatorDeviceUnique.size()==0 && userIdList.size() > 0){
            //此处处理电梯 对于设备而言既无新增又有添加，但该分组已有电梯权限的楼层发生变化时，则需将所选中设备赋值于 新增设备集合中
            addElevatorDeviceUnique.addAll(Arrays.asList(StringHandlerUtil.splitString(propertyHouseholdRoleAuthDTO.getDeviceUniques())));
        }
        if ((deleteDeviceUnique.size() > 0 || addDeviceUnique.size() > 0 || addElevatorDeviceUnique.size()>0 || deleteElevatorDeviceUnique.size()>0) && userIdList.size() > 0) {
            AppFaceRecognitionDeviceAuthDTO appFaceRecognitionDeviceAuthDTO = new AppFaceRecognitionDeviceAuthDTO();
            appFaceRecognitionDeviceAuthDTO.setAddDeviceUnique(addDeviceUnique);
            appFaceRecognitionDeviceAuthDTO.setDeleteDeviceUnique(deleteDeviceUnique);
            appFaceRecognitionDeviceAuthDTO.setDeleteElevatorDeviceUnique(deleteElevatorDeviceUnique);
            appFaceRecognitionDeviceAuthDTO.setAddElevatorDeviceUnique(addElevatorDeviceUnique);
            appFaceRecognitionDeviceAuthDTO.setUserIdList(userIdList);
            appFaceRecognitionDeviceAuthDTO.setDeviceType(deviceType);
            appFaceRecognitionDeviceAuthDTO.setProjectId(propertyHouseholdRoleAuthDTO.getProjectId());
            new Thread(() -> {
                try{
                    //推送人脸平板指令
                    iPadFaceSyncDataServiceClient.padDeviceAuth(appFaceRecognitionDeviceAuthDTO);

                    //此处处理推送动态人脸识别系统权限指令
                    if(userIdList!=null && userIdList.size()>0){
                        for(String userId : userIdList){
                            PadFaceSyncDataDTO padFaceSyncDataDTO = new PadFaceSyncDataDTO();
                            padFaceSyncDataDTO.setOperateType("6");
                            padFaceSyncDataDTO.setAppUserIds(userId);
                            padFaceSyncDataDTO.setProjectId(appFaceRecognitionDeviceAuthDTO.getProjectId());
                            padFaceSyncDataDTO.setStatus("1");
                            padFaceSyncDataDTO.setSourceSystem(2);
                            iPadFaceSyncDataServiceClient.userOrFloorSyncSmartCard(padFaceSyncDataDTO);
                        }
                    }
                } catch (Exception e) {
                    throw new DataAccessException("【物业-住户管理】修改住户角色组设备授权推送平板指令失败", e);
                }
            }).start();
        }
    }

    /**
     * <desc>
     *      住户角色组信息人员分配
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/02/22
     */
    @ResponseBody
    @PostMapping(path = "userAuth")
    @AuthAccessRequired
    @LoggerInfo(operateDesc = LogDescConstant.HOUSEHOLD_ROLE_USER_AUTH_LOG_DESC)
    public Object userAuth(PropertyHouseholdRoleAuthDTO propertyHouseholdRoleAuthDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyHouseholdRoleAuthDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyHouseholdRoleAuthDTO.class, request);
            if (propertyHouseholdRoleAuthDTO == null || StringUtils.isBlank(propertyHouseholdRoleAuthDTO.getRoleId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (StringUtils.isBlank(propertyHouseholdRoleAuthDTO.getProjectId())) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            //住户项目数据状态正常时才可分配，若住户已被冻结，则无法迁入(待优化)
            for (String userId : StringHandlerUtil.splitStringList(propertyHouseholdRoleAuthDTO.getUserIds())) {
                Integer userProjectStatus = iPropertyHouseHoldInfoServiceClient.getUserProjectStatusAtNormal(propertyHouseholdRoleAuthDTO.getProjectId(), userId);
                if (AppUserProjectStatusEnum.USERPROJECT_USERPROJECTSTATUS_FROZEN.getType().equals(userProjectStatus)) {
                    return new MessageVO(PropertyErrorCodeEnum.APP_USERS_USER_PROJECT_STATUS_FROZEN.getErrorCode());
                }
            }
            // 获取数据固化之前的用户列表
            List<String> userIdListOld = iPropertyHouseholdRoleServiceClient.getUserIdListByRoleId(propertyHouseholdRoleAuthDTO.getRoleId());
            // 先进行住户角色组的设备授权
            iPropertyHouseholdRoleServiceClient.userAuth(propertyHouseholdRoleAuthDTO);

            Thread.sleep(500);//保证数据一致性

            // 获取数据固化之前的用户列表
            List<String> userIdListNew = iPropertyHouseholdRoleServiceClient.getUserIdListByRoleId(propertyHouseholdRoleAuthDTO.getRoleId());

            Map<String,List<String>> resultMap = this.doPadUserBusiness(userIdListOld,userIdListNew,propertyHouseholdRoleAuthDTO.getRoleId(),propertyHouseholdRoleAuthDTO.getProjectId());
            List<String> deleteUser = resultMap.get("deleteUser");
            List<String> addUser = resultMap.get("addUser");
            List<String> updateUser = new ArrayList<>();
            if(deleteUser!=null && deleteUser.size()>0){
                updateUser.addAll(deleteUser);
            }
            if(addUser!=null && addUser.size()>0){
                updateUser.addAll(addUser);
            }
            List<Map<String,Object>> list = new ArrayList<>();
            for(String userId : updateUser) {
                //获取用户临时权限数据
                Map<String, Object> tempAuth = iPropertyHouseHoldInfoServiceClient.getOldUserTempAuth(userId, propertyHouseholdRoleAuthDTO.getProjectId());
                list.add(tempAuth);
            }

            // 再同步用户门禁设备权限表信息
            // 拿到角色绑定的门禁设备序列号列表
            List<String> deviceUniqueListByRoleId = iPropertyHouseholdRoleServiceClient.getDeviceUniqueListByRoleId(propertyHouseholdRoleAuthDTO.getRoleId(),"1");

            // 拿到当前项目所有普通门禁设备序列号字符串
            String currentDevices = iPropertyHouseholdRoleServiceClient.getAllDeviceUniqueStr(propertyHouseholdRoleAuthDTO.getProjectId());
            if (StringUtils.isBlank(currentDevices)) {
                currentDevices = "";
            }
            if (deviceUniqueListByRoleId != null && !deviceUniqueListByRoleId.isEmpty()) {
                for (String userId : StringHandlerUtil.splitStringList(propertyHouseholdRoleAuthDTO.getUserIds())) {
                    // 拿到角色绑定的门禁设备序列号列表
                    deviceUniqueListByRoleId = iPropertyHouseholdRoleServiceClient.getDeviceUniqueListByRoleId(propertyHouseholdRoleAuthDTO.getRoleId(),"1");
                    //由于一个人可以属于多个组，故此处还需取用户非当前分组的设备机号权限与当前分组的权限机号并集
                    List<String> notGroupEntrance = iPropertyHouseholdRoleServiceClient.getEntranceListByNotInRoleIdAndUserId(propertyHouseholdRoleAuthDTO.getRoleId(),userId,propertyHouseholdRoleAuthDTO.getProjectId());
                    if(notGroupEntrance!=null){
                        deviceUniqueListByRoleId.addAll(notGroupEntrance);
                    }
                    String deviceUniqueStrByRoleId = deviceUniqueListByRoleId.toString().replace("[", "").replace("]", "").replaceAll(" ","");
                    iPropertyDeviceAuthServiceClient.updateHouseHoldTmpDeviceAuth(propertyHouseholdRoleAuthDTO.getLoginUserId(), userId, propertyHouseholdRoleAuthDTO.getProjectId(), 2
                            , currentDevices, deviceUniqueStrByRoleId, new ArrayList<>(), "mark");
                }
                // 对于取消勾选的人员，需要删除掉门禁设备授权信息
                if (userIdListOld != null && !userIdListOld.isEmpty()) {
                    List<String> userIdNowList = StringHandlerUtil.splitStringList(propertyHouseholdRoleAuthDTO.getUserIds());
                    for (String userId : userIdListOld) {
                        if (!userIdNowList.contains(userId)) {
                            List<String> notGroupEntrance = iPropertyHouseholdRoleServiceClient.getEntranceListByNotInRoleIdAndUserId(propertyHouseholdRoleAuthDTO.getRoleId(),userId,propertyHouseholdRoleAuthDTO.getProjectId());
                            String notGroupEntranceStr = notGroupEntrance.toString().replace("[", "").replace("]", "").replaceAll(" ","");
                            iPropertyDeviceAuthServiceClient.updateHouseHoldTmpDeviceAuth(propertyHouseholdRoleAuthDTO.getLoginUserId(), userId, propertyHouseholdRoleAuthDTO.getProjectId(), 2
                                    , currentDevices, notGroupEntranceStr, new ArrayList<>(), "mark");
                        }
                    }
                }
            }
            //处理用户电梯设备权限表信息
             Map<String,Object> map = iPropertyHouseholdRoleServiceClient.getElevatorListByRoleId(propertyHouseholdRoleAuthDTO.getRoleId(),"1");
             if(map!=null && map.size()>0){
                 List<String> deviceUniqueByElevatorArr = (List<String>) map.get("deviceUniqueArr");
                 List<String> floorArr =(List<String>)  map.get("floorArr");
                // 拿到当前项目所有电梯设备序列号字符串
                String allElevatorDevices = iPropertyHouseholdRoleServiceClient.getAllElevatorDeviceUniqueStr(propertyHouseholdRoleAuthDTO.getProjectId());
                if (deviceUniqueByElevatorArr != null && !deviceUniqueByElevatorArr.isEmpty()) {
                    for (String userId : StringHandlerUtil.splitStringList(propertyHouseholdRoleAuthDTO.getUserIds())) {
                        //由于一个人可以属于多个组，故此处还需取用户非当前分组的设备机号权限与当前分组的权限机号 同一机号楼层取并集
                        Map<String,Object> notGroupMap = iPropertyHouseholdRoleServiceClient.getElevatorListByNotInRoleIdAndUserId("",userId,propertyHouseholdRoleAuthDTO.getProjectId());
                        String deviceUniqueStrElevatorByRoleId = "";
                        List<String> floorNotGroupArr = new ArrayList<>();
                        if(notGroupMap!=null && notGroupMap.size()>0){
                            List<String> deviceUniqueByNotGroupElevatorArr = (List<String>) notGroupMap.get("deviceUniqueArr");
                            floorNotGroupArr =(List<String>)  notGroupMap.get("floorArr");
                            //deviceUniqueByElevatorArr.addAll(deviceUniqueByNotGroupElevatorArr);
                            //floorArr.addAll(floorNotGroupArr);
                            deviceUniqueStrElevatorByRoleId = deviceUniqueByNotGroupElevatorArr.toString().replace("[", "").replace("]", "").replaceAll(" ","");
                        }
                        iPropertyDeviceAuthServiceClient.updateHouseHoldTmpDeviceAuth(propertyHouseholdRoleAuthDTO.getLoginUserId(), userId, propertyHouseholdRoleAuthDTO.getProjectId(), 1
                                , allElevatorDevices, deviceUniqueStrElevatorByRoleId, floorNotGroupArr, "mark");
                    }
                    // 对于取消勾选的人员，需要删除掉电梯设备授权信息
                    if (userIdListOld != null && !userIdListOld.isEmpty()) {
                        List<String> userIdNowList = StringHandlerUtil.splitStringList(propertyHouseholdRoleAuthDTO.getUserIds());
                        for (String userId : userIdListOld) {
                            if (!userIdNowList.contains(userId)) {
                                Map<String,Object> notGroupMap = iPropertyHouseholdRoleServiceClient.getElevatorListByNotInRoleIdAndUserId(propertyHouseholdRoleAuthDTO.getRoleId(),userId,propertyHouseholdRoleAuthDTO.getProjectId());
                                List<String> floorNotGroupArr = new ArrayList<>();
                                String deviceUniqueStrElevatorNotGroupByRoleId = "";
                                if(notGroupMap!=null && notGroupMap.size()>0){
                                    List<String> deviceUniqueByNotGroupElevatorArr = (List<String>) notGroupMap.get("deviceUniqueArr");
                                    floorNotGroupArr =(List<String>)  notGroupMap.get("floorArr");
                                    deviceUniqueStrElevatorNotGroupByRoleId = deviceUniqueByNotGroupElevatorArr.toString().replace("[", "").replace("]", "").replaceAll(" ","");
                                }
                                iPropertyDeviceAuthServiceClient.updateHouseHoldTmpDeviceAuth(propertyHouseholdRoleAuthDTO.getLoginUserId(), userId, propertyHouseholdRoleAuthDTO.getProjectId(), 1
                                        , allElevatorDevices, deviceUniqueStrElevatorNotGroupByRoleId, floorNotGroupArr, "mark");
                            }
                        }
                    }
                }
            }

            for(Map<String,Object> tempAuth : list) {
                //推送临时权限数据
                iPropertyHouseHoldInfoServiceClient.pushTempUserInfos(propertyHouseholdRoleAuthDTO.getProjectId(), tempAuth.get("userId").toString(), StringHandlerUtil.getNullOrStringForObject(tempAuth.get("doorAuth")),
                        StringHandlerUtil.getNullOrStringForObject(tempAuth.get("elevatorAuth")), StringHandlerUtil.getNullOrStringForObject(tempAuth.get("talkAuth")),"3");
            }

            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【物业-住户管理】住户角色组信息人员分配失败", e);
        }
    }

    /**
     * <desc>
     *      获取角色组电梯授权分页列表
     * </desc>
     *
     * @param
     * @return
     * @Author Zhu.yj
     * @createDate  2021/3/29
     */
    @PostMapping("/getElevatorPage")
    public Object getElevatorPage(PropertyHouseholdRoleGetPageDTO dto, HttpServletRequest request){
        try{
            dto = HttpProtocolUtil.parseRequestParamToDTO(PropertyHouseholdRoleGetPageDTO.class, request);
            if (dto == null || StringUtils.isBlank(dto.getRoleId())){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            Page<PropertyHouseHoldRoleElevatorGetPageVO> page = iPropertyHouseholdRoleServiceClient.getElevatorPage(dto);

            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), page);
        }catch (Exception e){
            throw new DataAccessException("【物业-住户权限分配】获取角色组电梯授权分页列表失败", e);
        }
    }



    /**
     * <desc>
     *      处理平板设备用户指令相关业务
     * </desc>
     *
     * @param userIdListOld 旧用户信息
     * @param userIdListNew 当前用户信息
     * @param roleId 角色编号
     * @param projectId 项目编号
     * @return 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2020/03/10
     */
    private Map<String,List<String>> doPadUserBusiness(List<String> userIdListOld, List<String> userIdListNew, String roleId, String projectId) throws Exception {
        //确认哪些用户新增,哪些用户取消
        List<String> deleteUser = new ArrayList<>();
        List<String> addUser = new ArrayList<>();
        for (String userOld : userIdListOld) {//旧的和新的比找出减少的
            int flag = 0;
            for (String userNew : userIdListNew) {
                if (userOld.equals(userNew)) {
                    flag = 1;
                    break;
                }
            }
            if (flag == 0) {//没有任何一样的证明是减少了的设备
                deleteUser.add(userOld);
            }
        }

        for (String userNew : userIdListNew) {//新的和旧的比找出新增的
            int flag = 0;
            for (String userOld : userIdListOld) {
                if (userNew.equals(userOld)) {
                    flag = 1;
                    break;
                }
            }
            if (flag == 0) {//没有任何一样的证明是新增了的设备
                addUser.add(userNew);
            }
        }
        Map<String,List<String>> returnMap = new HashMap<>();
        returnMap.put("addUser",addUser);
        returnMap.put("deleteUser",deleteUser);
        //过滤无人脸的用户
        if (deleteUser.size() > 0) {
            deleteUser = iPropertyHouseholdRoleServiceClient.getUserHaveFace(deleteUser,projectId);
        }
        if (addUser.size() > 0) {
            addUser = iPropertyHouseholdRoleServiceClient.getUserHaveFace(addUser,projectId);
        }
        //查询组内所对应的门禁设备
        List<String> deviceUniqueListByRoleId = iPropertyHouseholdRoleServiceClient.getDeviceUniqueListByRoleId(roleId,"1");
        //查询组内所对应的电梯设备
        Map<String,Object> map = iPropertyHouseholdRoleServiceClient.getElevatorListByRoleId(roleId,"1");
        List<String> deviceUniqueByElevatorArr =new ArrayList<>();
        AppElevatorAuthVO elevatorAuthVO = new AppElevatorAuthVO();
        if(map!=null && map.size()>0){
            deviceUniqueByElevatorArr = (List<String>) map.get("deviceUniqueArr");
            List<String> floorArr = (List<String>) map.get("deviceUniqueArr");
            elevatorAuthVO = JSON.parseObject(JSON.toJSONString(map.get("elevator")),AppElevatorAuthVO.class);
        }

        //平板普通门禁业务指令处理
        if ((deleteUser.size() > 0 || addUser.size() > 0) && (deviceUniqueListByRoleId.size() > 0 || deviceUniqueByElevatorArr.size()>0)) {
            AppFaceRecognitionDeviceAuthDTO appFaceRecognitionDeviceAuthDTO = new AppFaceRecognitionDeviceAuthDTO();
            appFaceRecognitionDeviceAuthDTO.setAddUser(addUser);
            appFaceRecognitionDeviceAuthDTO.setDeleteUser(deleteUser);
            appFaceRecognitionDeviceAuthDTO.setDeviceUniqueListByRoleId(deviceUniqueListByRoleId);
            appFaceRecognitionDeviceAuthDTO.setDeviceUniqueByElevatorArr(deviceUniqueByElevatorArr);
            appFaceRecognitionDeviceAuthDTO.setElevatorAuthVO(elevatorAuthVO);
            appFaceRecognitionDeviceAuthDTO.setProjectId(projectId);
            appFaceRecognitionDeviceAuthDTO.setRoleId(roleId);
            List<String> totalUserInfo = new ArrayList<>();
            totalUserInfo.addAll(deleteUser);
            totalUserInfo.addAll(addUser);
            new Thread(() -> {
                try{
                    //推送平板指令
                    iPadFaceSyncDataServiceClient.padUserAuth(appFaceRecognitionDeviceAuthDTO);

                    //此处处理推送动态人脸识别系统权限指令
                    if(totalUserInfo!=null && totalUserInfo.size()>0){
                        for(String userId : totalUserInfo){
                            PadFaceSyncDataDTO padFaceSyncDataDTO = new PadFaceSyncDataDTO();
                            padFaceSyncDataDTO.setOperateType("6");
                            padFaceSyncDataDTO.setAppUserIds(userId);
                            padFaceSyncDataDTO.setProjectId(appFaceRecognitionDeviceAuthDTO.getProjectId());
                            padFaceSyncDataDTO.setStatus("1");
                            padFaceSyncDataDTO.setSourceSystem(2);
                            iPadFaceSyncDataServiceClient.userOrFloorSyncSmartCard(padFaceSyncDataDTO);
                        }
                    }
                } catch (Exception e) {
                    throw new DataAccessException("【物业-住户管理】修改住户角色组人员授权推送平板指令失败", e);
                }
            }).start();
        }
        return returnMap;
    }

    /**
     * <desc>
     *      组装查询App用户信息返回给前端
     * <desc/>
     *
     * @param appUserInfoGetVOS 返回给前端的物业住户信息对象
     * @return List<AppUserInfoGetAssembleVO> 组装过的返回给前端使用物业住户信息
     * @author zhangs
     * @createDate 2017/09/26
     */
    private List<AppUserInfoGetAssembleVO> assembleAppUserInfoGetVO(List<AppUserInfoGetVO> appUserInfoGetVOS) {
        //返回结果
        List<AppUserInfoGetAssembleVO> appUserInfoGetAssembleVOS = new ArrayList<>();
        //用于组装合并数据
        Map<String, AppUserInfoGetAssembleVO> map = new HashMap<>();
        LinkedHashMap<String, AppUserInfoGetAssembleVO> linkedHashMap = new LinkedHashMap<>();
        //记录住户
//        Set<String> userIdSet = new HashSet<>();
        LinkedHashSet<String> userIdSet = new LinkedHashSet<>();
        if (appUserInfoGetVOS.isEmpty()) {
            return appUserInfoGetAssembleVOS;
        }
        //遍历
        for (AppUserInfoGetVO appUserInfoGetVO : appUserInfoGetVOS) {
            String userId = appUserInfoGetVO.getUserId();
            userIdSet.add(userId);
            //相同住户合并住户房间信息
            if (linkedHashMap.get(userId) == null) {
//            if (map.get(userId) == null) {
                List<AppUserInfoGetRoomVO> appUserInfoGetRoomVOS = new ArrayList<>();
                AppUserInfoGetRoomVO appUserInfoGetRoomVO = new AppUserInfoGetRoomVO();
                BeanUtils.copyProperties(appUserInfoGetVO, appUserInfoGetRoomVO);
                appUserInfoGetRoomVOS.add(appUserInfoGetRoomVO);
                AppUserInfoGetAssembleVO appUserInfoGetAssembleVO =
                        new AppUserInfoGetAssembleVO(userId, appUserInfoGetVO.getRealName(), appUserInfoGetVO.getPhoneNum(),
                                appUserInfoGetVO.getQqNum(), appUserInfoGetVO.getCreateUserTime(),
                                appUserInfoGetVO.getUpdateTime(), appUserInfoGetVO.getIsFace(), appUserInfoGetVO.getIsBindingIdcard(), appUserInfoGetVO.getIsLoss(),appUserInfoGetRoomVOS);
//                map.put(userId, appUserInfoGetAssembleVO);
                linkedHashMap.put(userId, appUserInfoGetAssembleVO);
            } else {
//                AppUserInfoGetAssembleVO appUserInfoGetAssembleVO = map.get(userId);
                AppUserInfoGetAssembleVO appUserInfoGetAssembleVO = linkedHashMap.get(userId);
                List<AppUserInfoGetRoomVO> appUserInfoGetRoomVOS = appUserInfoGetAssembleVO.getAppUserInfoGetRoomVOS();
                AppUserInfoGetRoomVO appUserInfoGetRoomVO = new AppUserInfoGetRoomVO();
                BeanUtils.copyProperties(appUserInfoGetVO, appUserInfoGetRoomVO);
                appUserInfoGetRoomVOS.add(appUserInfoGetRoomVO);
                appUserInfoGetAssembleVO.setAppUserInfoGetRoomVOS(appUserInfoGetRoomVOS);
//                map.put(userId, appUserInfoGetAssembleVO);
                linkedHashMap.put(userId, appUserInfoGetAssembleVO);
            }
        }
        for (String userId : userIdSet) {
//            appUserInfoGetAssembleVOS.add(map.get(userId));
            appUserInfoGetAssembleVOS.add(linkedHashMap.get(userId));
        }
        return appUserInfoGetAssembleVOS;
    }

}
